<?php

namespace App\Admin\Forms;

use App\Admin\Repositories\WxUserTemp;
use App\Models\WxUser;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use App\Models\WxFeedback as FeedbackModel;
use App\Models\WxNotice as NoticeModel;

class UserTempForms extends Form implements LazyRenderable
{
    use LazyWidget;


    /**
     * 主题颜色.
     *
     * @var array
     */
    protected $status = [
        1 => '审核通过',
        2 => '驳回',
    ];

    /**
     * 处理表单请求.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {

        $id = $input['id'];
        $status = $input['comment_status'];
        WxUserTemp::where('id',$id)->update([
            'user_state'=> $status
        ]);
        $data = WxUserTemp::where('id',$id)->first();
        $user = new WxUser();
        $user->id = $data['user_id'];
        $user->user_avatar = $data['user_avatar'];
        $user->user_name = $data['user_name'];
        $user->user_introduce = $data['user_introduce'] ? $data['user_introduce']:'';
        $user->user_birthday = $data['user_birthday'];
        $user->user_background_maps = $data['user_background_maps'];
       $user->save();


        return $this->response()
            ->success('操作成功.')
            ->refresh();
    }

    /**
     * 构建表单.
     */
    public function form()
    {
        $this->hidden('id')->value($this->payload["id"]);
        $this->radio('comment_status', "状态")->options($this->status)->default(1);

    }

}
